<template>
	<view class="content">
		<bgyx-nav-bar>
			<view slot="left">
				<image :src="`/static/images/link${$store.state.websocket.connectState ? 's' : 'f'}.png`"
					style="width: 60rpx;height: 60rpx;" mode=""></image>
			</view>
			<view slot="default">
				<b style="font-size: 32rpx;">朋友圈</b>
			</view>
			<view slot="right" style="display: flex;justify-content: flex-end;align-items: center;">
				<image @click="pubInfo" style="width: 45rpx;height: 45rpx;margin-right: 10rpx;" src="/static/images/icon_pub.png" />
			</view>
		</bgyx-nav-bar>
		
		<view v-for="(item,index) in list" style="width: 100%;display: flex;flex-direction: column;">
			<view style="display: flex;padding: 30rpx;">
				<image :src="item.avatar" style="width: 80rpx;height: 80rpx;margin-right: 15rpx;border-radius: 8rpx;" mode=""></image>
				<view style="display: flex;flex-direction: column;flex: 1;">
					<view style="font-weight: 500;color: #2f58af;display: flex;width: 100%;justify-content: space-between;">
						<text>{{item.name}}</text>
						<text style="color: #cbcbcb;">{{$u.timeFormat(item.time, 'mm-dd hh:MM:ss')}}</text>
					</view>
					<view style="margin: 6rpx 0rpx;">
						{{item.content}}
					</view>
					<view style="width: 100%;">
						<pyqimagesview :list="item.images" />
					</view>
				</view>
			</view>
		</view>
		
		<view v-if="!$store.state.friend.more" style="display: flex;width: 100%;margin: 30rpx auto;text-align: center;color: #bababa;justify-content: center;">
			—— 没有更多数据了 ——
		</view>
		
		<u-tabbar></u-tabbar>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import pyqimagesview from './components/pyqimagesview.vue'
	export default {
		data() {
			return {
				title: 'Hello',
			}
		},
		components:{
			pyqimagesview
		},
		computed: {
			...mapState({
				// 从state中拿到数据 箭头函数可使代码更简练
				list: state => {
					const list = state.friend.list.map(e=>{
						if(typeof e.images == "string"){
							e.images = (e.images && e.images.length > 0) ? JSON.parse(e.images) : []
							return e
						}else{
							return e
						}
					})
					console.log(114477,list)
					return list
				}
			})
		},
		onLoad() {
			this.$event.sub("ces",function(e){
				console.log(e)
			})
		},
		onShow() {
			if(!this.list || this.list.length == 0){
				this.$store.dispatch({
					type: "friend/refreshListForce",
					payload: {}
				})
			}
		},
		onPullDownRefresh() {
			this.$store.dispatch({
				type:"friend/refreshListForce",
				payload:{}
			})
			setTimeout(()=>{
				uni.stopPullDownRefresh()
			},1000)
			
		},
		onReachBottom() {
			if(!this.$store.state.friend.more){
				return
			}
			uni.showLoading({
				title:"加载中..."
			})
			this.$store.dispatch({
				type:"friend/refreshList",
				payload:{}
			})
			setTimeout(()=>{
				uni.hideLoading()
			},1500)
		},
		methods: {
			pubInfo:function(){
				console.log(112233)
				uni.navigateTo({
					url:"/pages/friends/pubinfo"
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 100rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 28rpx;
		color: $u-content-color;
	}

	.button-demo {
		margin-top: 80rpx;
	}

	.link-demo {
		margin-top: 80rpx;
	}
</style>